package top.ffhome.common.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@ApiModel
public class Result {
	@Getter
	@Setter
	@ApiModelProperty(value = "返回码，0表示成功返回")
	private int code;
	@Getter
	@Setter
	@ApiModelProperty(value = "返回信息")
	private String message;
	@Getter
	@Setter
	@ApiModelProperty(value = "返回数据")
	private Object data;

	Result(int code, String message, Object data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public static Result success() {
		return success(null, null);
	}

	public static Result success(Object data) {
		return success(null, data);
	}

	public static Result success(String message, Object data) {
		return build(ResultCode.SUCCESS, message, data);
	}

	public static Result fail(String message) {
		return build(ResultCode.FAIL, message, null);
	}

	public static Result fail(int resultCode, String message) {
		return build(resultCode, message, null);
	}

	public static Result build(ResultCode resultCode, String message, Object data) {
		return build(resultCode.code, message, data);
	}

	public static Result build(int resultCode, String message, Object data) {
		return new Result(resultCode, message, data);
	}
}
